﻿using System;
using System.Collections.Generic;

using System.Text;
using System.ComponentModel;
using System.Drawing;
using ITAP.ShprossesBuilder.Modelling.Components;

namespace ITAP.ShprossesBuilder.ShprossesPropertyGrid.ComponentsProxy
{
    public class ModelCellProxy : Proxy
    {
        private ModelCell modelCell;
        public ModelCellProxy(ModelCell modelCell, MainControl mainControl) : base(mainControl)
        {
            this.modelCell = modelCell;
        }

        //[Category("Выравнивание"), DisplayName("По горизонтали"), Description("Выравнивание модели внутри ячейки по горизонтали.")]
        //public HorizontalAlign HorizontalModelAlign
        //{
        //    get { return modelCell.HorizontalModelAlign; }
        //    set 
        //    {
        //        this.ExecutePropertyValueChangingCommand();
        //        modelCell.HorizontalModelAlign = value; 
        //    }
        //}

        //[Category("Выравнивание"), DisplayName("По вертикали"), Description("Выравнивание модели внутри ячейки по вертикали.")]
        //public VerticalAlign VerticalModelAlign
        //{
        //    get { return modelCell.VerticalModelAlign; }
        //    set 
        //    {
        //        this.ExecutePropertyValueChangingCommand();
        //        modelCell.VerticalModelAlign = value; 
        //    }
        //}

        //[Category("Положение модели"), DisplayName("X")]
        //public double HorizontalPosition
        //{
        //    get
        //    {
        //        return Math.Round(modelCell.Model.Position.X, 1, MidpointRounding.ToEven);
        //    }
        //    set
        //    {
        //        if (modelCell.HorizontalModelAlign == HorizontalAlign.None)
        //        {
        //            this.ExecutePropertyValueChangingCommand();
        //            modelCell.Model.Position = new Shprosses.Modelling.ModelPoint(value, modelCell.Model.Position.Y);
        //        }
        //    }
        //}

        //[Category("Положение модели"), DisplayName("Y")]
        //public double VerticalPosition
        //{
        //    get
        //    {
        //        return Math.Round(modelCell.Model.Position.Y, 1, MidpointRounding.ToEven);
        //    }
        //    set
        //    {
        //        if (modelCell.VerticalModelAlign == VerticalAlign.None)
        //        {
        //            this.ExecutePropertyValueChangingCommand();
        //            modelCell.Model.Position = new Shprosses.Modelling.ModelPoint(modelCell.Model.Position.X, value);
        //        }
        //    }
        //}


        [Category("Отступы"), DisplayName("По горизонтали")]
        public double XOffset
        {
            get
            {
                return modelCell.OffsetX;

                //double result;
                //RectangleF cellBBox = modelCell.BoundingBox;
                //RectangleF modelBBox = modelCell.Model.BoundingBox;
                //switch (modelCell.HorizontalModelAlign)
                //{
                //    case HorizontalAlign.Center:
                //        result = modelBBox.X + modelBBox.Width / 2 - cellBBox.X - cellBBox.Width / 2;
                //        break;
                //    case HorizontalAlign.Left:
                //        result = modelBBox.X - cellBBox.X;
                //        break;
                //    case HorizontalAlign.Right:
                //        result = cellBBox.X + cellBBox.Width - modelBBox.X - modelBBox.Width;
                //        break;
                //    default:
                //        result = 0;
                //        break;
                //}
                //return Math.Round(result, 1, MidpointRounding.ToEven);
            }
            set
            {
                this.ExecutePropertyValueChangingCommand();

                modelCell.OffsetX = value;

                modelCell.MoveModelTo(modelCell.HorizontalModelAlign);

                //switch (modelCell.HorizontalModelAlign)
                //{
                //    case HorizontalAlign.Center:
                //        modelCell.Model.MoveWithOffset(new Shprosses.Modelling.ModelVector(value, 0));
                //        break;
                //    case HorizontalAlign.Left:
                //        modelCell.Model.MoveWithOffset(new Shprosses.Modelling.ModelVector(value, 0));
                //        break;
                //    case HorizontalAlign.Right:
                //        modelCell.Model.MoveWithOffset(new Shprosses.Modelling.ModelVector(-value, 0));
                //        break;
                //    default:
                //        return;
                //}
            }
        }

        [Category("Отступы"), DisplayName("По вертикали")]
        public double YOffset
        {
            get
            {
                return modelCell.OffsetY;
                //double result;
                //RectangleF cellBBox = modelCell.BoundingBox;
                //RectangleF modelBBox = modelCell.Model.BoundingBox;
                //switch (modelCell.VerticalModelAlign)
                //{
                //    case VerticalAlign.Center:
                //        result = modelBBox.Y + modelBBox.Height / 2 - cellBBox.Y - cellBBox.Height / 2;
                //        break;
                //    case VerticalAlign.Top:
                //        result = cellBBox.Height - modelBBox.Height;
                //        break;
                //    case VerticalAlign.Bottom:
                //        result = modelBBox.Y - cellBBox.Y;
                //        break;
                //    default:
                //        result = 0;
                //        break;
                //}
                //return Math.Round(result, 1, MidpointRounding.ToEven);

            }
            set
            {
                this.ExecutePropertyValueChangingCommand();
                modelCell.OffsetY = value;
                modelCell.MoveModelTo(modelCell.VerticalModelAlign);
                //switch (modelCell.VerticalModelAlign)
                //{
                //    case VerticalAlign.Center:
                //        modelCell.Model.MoveWithOffset(new Shprosses.Modelling.ModelVector(0, -value));
                //        break;
                //    case VerticalAlign.Top:
                //        modelCell.Model.MoveWithOffset(new Shprosses.Modelling.ModelVector(0, -value));
                //        break;
                //    case VerticalAlign.Bottom:
                //        modelCell.Model.MoveWithOffset(new Shprosses.Modelling.ModelVector(0, value));
                //        break;
                //    default:
                //        return;
                //}
            }
        }

    }
}
